A circular queue, or circular first-in-first-out (FIFO) memory structure, typically utilizes a block of sequential locations (a queue storage area) in a random access memory (RAM) for the storage of queue entries. A head pointer indicates the address of a first valid queue entry within the RAM, while a tail pointer indicates the address of the queue entry immediately after the last valid entry within the RAM. The head and tail pointers are typically stored outside the queue storage area, either within the RAM or associated registers.
By comparing the head and tail pointers, a determination can be made regarding the number of entries within a queue. A comparison of the head and tail pointers can also be performed with a view to assessing whether a queue is completely empty or completely full. It is often also useful to know whether a queue is nearly empty or nearly full. Near-empty and near-full warnings can then be issued to avoid queue underflow and overflow errors, respectively. Underflow is caused by a dequeue on an empty queue, while overflow is caused by an enqueue on a full queue.